package dk.android.houseenabler;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;

public class SplashScreenActivity extends Activity{
    
	protected boolean _active = true;
	protected int _splashTime = 5000;
	
	
	/** Called when the activity is first created. */
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splach_screen);
        
       
     // thread for displaying the SplashScreen
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    int waited = 0;
                    while(_active && (waited < _splashTime)) {
                    	Thread.sleep(100);
                        if(_active) {
                            waited += 100;
                        }
                    }
                } catch(InterruptedException e) {
                    // do nothing
                } finally {
                    finish();
                    //loading the intented activity
                    startActivity(new Intent("dk.android.houseenabler.splashscreen.HouseenablerActivity"));
                    
                }
            }
        }).start();
    }
	// Using this metode and when the _active is set to false, the splashscreen cant start. 
	@Override
	public boolean onTouchEvent(MotionEvent event) 
	{
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
        _active = false;
    }
    return true;
}
            
}
